package gokyesil.game2d.actors;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class ToolButton extends Button 
{
	private boolean alpha;
	public ToolButton(Texture up, Texture down, Texture checked, float x, float y, int width, int height)
	{
		super(new TextureRegionDrawable(new TextureRegion(up)),new TextureRegionDrawable(new TextureRegion(down)),new TextureRegionDrawable(new TextureRegion(checked)) );
		this.setPosition(x, y);
		this.setWidth(width);
		this.setHeight(height);
		this.setChecked(false);
		alpha = false;
	}
	public ToolButton(Texture texture, float x, float y, int width, int height)
	{
		super(new TextureRegionDrawable(new TextureRegion(texture)));
		this.setPosition(x, y);
		this.setWidth(width);
		this.setHeight(height);
		alpha = false;
	}
	public ToolButton()
	{
		super();
		this.setVisible(false);
		this.setTouchable(Touchable.disabled);
		this.setTransform(true);
		alpha = true;
		
	}
	public void set(ButtonStyle style,float x, float y, float scale)
	{
		this.setStyle(style);
		this.setWidth(((TextureRegionDrawable)style.up).getRegion().getTexture().getWidth());
		this.setHeight(((TextureRegionDrawable)style.up).getRegion().getTexture().getHeight());
		this.setVisible(true);
		this.setScale(scale);
		this.setPosition(x-this.getScaleX()*this.getWidth()/2, y-this.getScaleY()*this.getHeight()/2);
	}
	public void draw(Batch batch, float parentAlpha)
	{
		if(alpha)
			super.draw(batch, 0.4f);
		else
			super.draw(batch, parentAlpha);
	}
	public void zoom(boolean isZoomIn)
	{
		if(isZoomIn && this.getScaleX() < 2.0f)
			this.scaleBy(0.1f);
		if(!isZoomIn && this.getScaleY() > 0.5f)
			this.scaleBy(-0.1f);
	}
	
}
